package com.ruoyi.fep.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.fep.domain.Orders;
import com.ruoyi.fep.domain.Products;
import com.ruoyi.fep.mapper.OrdersMapper;
import com.ruoyi.fep.mapper.ProductsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fep.mapper.OrdersDetailsMapper;
import com.ruoyi.fep.domain.OrdersDetails;
import com.ruoyi.fep.service.IOrdersDetailsService;

/**
 * 订单详情Service业务层处理
 * 
 * @author zj
 * @date 2023-04-12
 */
@Service
public class OrdersDetailsServiceImpl implements IOrdersDetailsService 
{
    @Autowired
    private OrdersDetailsMapper ordersDetailsMapper;
    @Autowired
    private OrdersMapper ordersMapper;

    @Autowired

    private ProductsMapper productsMapper;

    /**
     * 查询订单详情
     * 
     * @param id 订单详情主键
     * @return 订单详情
     */
    @Override
    public OrdersDetails selectOrdersDetailsById(Long id)
    {
        return ordersDetailsMapper.selectOrdersDetailsById(id);
    }

    /**
     * 查询订单详情列表
     * 
     * @param ordersDetails 订单详情
     * @return 订单详情
     */
    @Override
    public List<OrdersDetails> selectOrdersDetailsList(OrdersDetails ordersDetails)
    {
        List<OrdersDetails> ordersDetailsList = ordersDetailsMapper.selectOrdersDetailsList(ordersDetails);
        for (int i = 0; i <ordersDetailsList.size() ; i++) {
            OrdersDetails details = ordersDetailsList.get(i);
            String orderNo = details.getOrderNo();
            System.out.println("----------"+orderNo);
           Orders orders = ordersMapper.selectOrdersByOrderNo(orderNo);
           System.out.println("jh_"+orders);
           details.setOrders(orders);

            Long productId = details.getProductId();
            Products products = productsMapper.selectProductsByProductId(productId);
            details.setProducts(products);


        }
        return ordersDetailsList;
    }
    /**
     * 新增订单详情
     * 
     * @param ordersDetails 订单详情
     * @return 结果
     */
    @Override
    public int insertOrdersDetails(OrdersDetails ordersDetails)
    {
        ordersDetails.setCreateTime(DateUtils.getNowDate());
        return ordersDetailsMapper.insertOrdersDetails(ordersDetails);
    }

    /**
     * 修改订单详情
     * 
     * @param ordersDetails 订单详情
     * @return 结果
     */
    @Override
    public int updateOrdersDetails(OrdersDetails ordersDetails)
    {
        ordersDetails.setUpdateTime(DateUtils.getNowDate());
        return ordersDetailsMapper.updateOrdersDetails(ordersDetails);
    }

    /**
     * 批量删除订单详情
     * 
     * @param ids 需要删除的订单详情主键
     * @return 结果
     */
    @Override
    public int deleteOrdersDetailsByIds(Long[] ids)
    {
        return ordersDetailsMapper.deleteOrdersDetailsByIds(ids);
    }

    /**
     * 删除订单详情信息
     * 
     * @param id 订单详情主键
     * @return 结果
     */
    @Override
    public int deleteOrdersDetailsById(Long id)
    {
        return ordersDetailsMapper.deleteOrdersDetailsById(id);
    }
}
